"""
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkRegularStepGradientDescentBaseOptimizer.cxx,v $
  Language:  C++
  Date:      $Date: 2007-09-10 16:22:23 $
  Version:   $Revision: 1.24 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
Translated to python on Jul 19, 2009

@Author: bryan

"""

#===============================================================================
# Imports
#===============================================================================
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import * 
from PyQt4 import QtCore, QtGui
import sys
import JT

#===============================================================================
# Main Class
#===============================================================================
def main():
    '''
    '''
    
    app = QtGui.QApplication(sys.argv) 
    tabs = True#False# 
    mainWindow = QtGui.QMainWindow()

    if tabs:
        tabWidget = QtGui.QTabWidget(mainWindow) 
        mainWindow.setCentralWidget(tabWidget) 
        frameWidget = QtGui.QFrame(mainWindow) 
        hbox1 = QtGui.QHBoxLayout() 
        hbox2 = QtGui.QHBoxLayout()
        vbox1 = QtGui.QVBoxLayout()
        frameWidget2 = QtGui.QFrame(mainWindow) 
        hbox3 = QtGui.QHBoxLayout() 
        hbox4 = QtGui.QHBoxLayout()
        vbox2 = QtGui.QVBoxLayout()
        
        iren1 = cone_iren_generator(frameWidget,resolution=10) 
        iren2 = cone_iren_generator(frameWidget,resolution=20)
        iren3 = cone_iren_generator(frameWidget2,resolution=30,
                                    color=(.1,.2,.7))
        iren4 = cone_iren_generator(frameWidget2,resolution=90,
                                    color=(.7,.2,.1))
    else:         
        frameWidget = QtGui.QFrame(mainWindow) 
        hbox = QtGui.QHBoxLayout() 
        mainWindow.setCentralWidget(frameWidget) 
        iren = QVTKRenderWindowInteractor(frameWidget) 
        iren2 = QVTKRenderWindowInteractor(frameWidget)
    
    if tabs: 
        hbox1.addWidget(iren1)
        hbox1.addWidget(iren2)
        hbox2.addWidget(iren3)
        hbox2.addWidget(iren4)
        #vbox1.addItem(hbox1)
        #vbox1.addItem(hbox2)
        frameWidget.setLayout(hbox1) 
        #vbox2.addItem(b)
        frameWidget2.setLayout(hbox2) 
        tabWidget.addTab(frameWidget,"Low Res Cone") 
        tabWidget.addTab(frameWidget2,"High Res Cone") 
    else: 
        hbox.addWidget(iren) 
        hbox.addWidget(iren2) 
        frameWidget.setLayout(hbox)
    
    mainWindow.show() 
    app.exec_()
    
def cone_iren_generator(parent_obj,resolution=10,color=(1.0,1.0,1.0)):
    """
    Return a vtk cone actor with resolution
    """
    cone = vtk.vtkConeSource()
    cone.SetResolution(resolution)
    
    coneMapper = vtk.vtkPolyDataMapper() 
    coneMapper.SetInput(cone.GetOutput()) 
    coneMapper.SetScalarRange(0,1)
    
    coneActor = vtk.vtkActor() 
    coneActor.SetMapper(coneMapper)
    props = coneActor.GetProperty()
    props.SetColor(color)

    iren = QVTKRenderWindowInteractor(parent_obj) 
    
    renderer = vtk.vtkRenderer() 
    renderer.AddActor(coneActor)
    
    renWin = iren.GetRenderWindow() 
    renWin.AddRenderer(renderer)
    
    iren.Initialize()
    
    return iren

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore


class InputDialog(QtGui.QDialog):
    def __init__(self, settings, parent=None):
        QtGui.QDialog.__init__(self, parent)
        
        self.setGeometry(300, 300, 350, 80)
        self.setWindowTitle('InputDialog')
        
        gridLayout = QtGui.QGridLayout()
        self.setLayout(gridLayout)
        labelList = []
        self.inputList = []
        self.data = []
        for i,item in enumerate(settings):
            labelList.append(QtGui.QLabel(item))
            self.inputList.append(QtGui.QLineEdit())
            self.inputList[-1].setText(str(settings[item]))
            gridLayout.addWidget(labelList[-1],i,0)
            gridLayout.addWidget(self.inputList[-1],i,1)
            self.connect(self.inputList[-1],
                         QtCore.SIGNAL("textEdited (const QString&)"),
                         self.updateText)
        self.updateText()
        button = QtGui.QPushButton('OK')
        self.connect(button,
                         QtCore.SIGNAL("clicked()"),
                         self.closeDialog)
        gridLayout.addWidget(button,i+1,1)
        
    def updateText(self):
        self.data = []
        for i in self.inputList:
            self.data.append(i.text())
            
    def closeDialog(self):
        self.done(11)
        

if __name__ == '__main__':
    #QtGui.QApplication.setStyle('cleanlooks')
    app = QtGui.QApplication(sys.argv)
    settings={'name':'mickey','job':'mouse','age':132}
    dlg = InputDialog(settings)
    print dlg.exec_()
    print dlg.data
    
    
        